<template>
    <div class="views-tongji1">
        <div>
            <el-form action="javascript:;" @submit="searchSubmit" inline>
                <el-form-item label="分类">
                    <el-select v-model="search.fenlei"
                        ><el-option label="请选择" value=""></el-option><e-select-option type="option" module="dianyingfenlei" value="id" label="fenleimingcheng"></e-select-option
                    ></el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" @click="searchSubmit">搜索</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <v3-echarts :options="barOptions" width="100%" height="300px"></v3-echarts>
        </div>
    </div>
</template>

<script setup>
    import http from "@/utils/ajax/http";
    import DB from "@/utils/db";

    import { ref, reactive, watch, computed, unref } from "vue";
    import { useRoute } from "vue-router";
    import { session } from "@/utils/utils";
    import { extend } from "@/utils/extend";

    const route = useRoute();

    const search = reactive({ fenlei: "" });
    extend(search, route.query);
    const searchSubmit = () => {
        loadDatabaseList();
    };
    var timer;
    watch(
        () => search,
        () => {
            clearTimeout(timer);
            timer = setTimeout(() => {
                searchSubmit();
            }, 200);
        },
        { deep: true }
    );
    const dianyingxinxiList = ref([]);
    const loadDatabaseList = async () => {
        var where = " 1=1 ";
        if (search.fenlei) {
            where += ` AND fenlei='${search.fenlei}' `;
        }
        dianyingxinxiList.value = await DB.name("dianyingxinxi").field("count(*) count").field("fenlei").group("fenlei").where(where).select();
    };

    loadDatabaseList();
    const barOptions = computed(() => {
        var list = unref(dianyingxinxiList);
        return {
            title: {
                text: "类型占比",
                left: "center",
            },
            tooltip: {
                trigger: "item",
            },
            legend: {
                orient: "vertical",
                left: "left",
            },
            series: [
                {
                    name: "电影信息数量",
                    type: "pie",
                    radius: "50%",
                    data: list.map((s) => {
                        return {
                            value: parseFloat(s.count),
                            name: s.fenlei,
                        };
                    }),
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: "rgba(0, 0, 0, 0.5)",
                        },
                    },
                },
            ],
        };
    });
</script>

<style scoped lang="scss">
    .views-tongji1 {
    }
</style>
